package com.sport.facilities.booking.system.httptask;

import java.util.List;

import android.content.Context;
import android.util.Log;

import com.sport.facilities.booking.system.htmlchecker.InquireConfirmedPageChecker;
import com.sport.facilities.booking.system.model.Booking;

public class InquireConfirmedTask extends BasicTask {
	private final String TAG = "InquireConfirmedTask";
	
	public InquireConfirmedTask(Context ctx, OnTaskCompleted completeAction) {
		super(ctx);
		this.listener = completeAction;
	}

	public void fnGetConfirmedList() {
		try {
			super.onPreExecute();
			super.execute(PATH_INQ_CONFIRM);
		} catch (Exception e) {
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	@Override
	protected void onPostExecute(String result) {
		super.onPostExecute(result);
		Log.d(TAG, "onPostExecute");
		InquireConfirmedPageChecker icbChecker = new InquireConfirmedPageChecker();
		List<Booking> bookingList = null;
		try {
			bookingList = icbChecker.getConfirmListfromHtml(result);
			this.listener.onTaskCompleted(bookingList);
		} catch (Exception e) {
			Log.e(TAG, "onPostExecuteException:"+e);
			this.listener.onTaskFailed(e.getMessage());
		}
	}

	public void setCompletedAction(OnTaskCompleted completeAction) {
		this.listener = completeAction;
	}

	/*
	 * Sample of the HTTP Request
	 */

	// Request URL:https://www40.polyu.edu.hk/saosport/spclaimed
	// Request Method:POST
	// Status Code:200 OK
	// Request Headersview source
	// Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
	// Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
	// Accept-Encoding:gzip,deflate,sdch
	// Accept-Language:en-US,en;q=0.8
	// Cache-Control:max-age=0
	// Connection:keep-alive
	// Content-Length:0
	// Content-Type:application/x-www-form-urlencoded
	// Cookie:JSESSIONID=0001IcRd-AFMb4aeqoZEzaimimC:-H419MD
	// Host:www40.polyu.edu.hk
	// Origin:https://www40.polyu.edu.hk
	// Referer:https://www40.polyu.edu.hk/saosport/spitems
	// User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like
	// Gecko) Chrome/23.0.1271.64 Safari/537.11
	// Response Headersview source
	// Connection:Keep-Alive
	// Content-Language:en-US
	// Content-Length:2810
	// Content-Type:text/html; charset=UTF-8
	// Date:Mon, 19 Nov 2012 09:02:17 GMT
	// Keep-Alive:timeout=5, max=100
	// Server:IBM_HTTP_Server

}
